package game.gui.panelvue;

import game.controler.ServeurFleches;
import game.controler.ControlerPanelVue;
import game.controler.EtatJeu;
import game.controler.gestionnaires.elementjeu.GestionnairePlans;
import game.gui.panelsplash.PanelSplashScreen;
import game.model.Plan;
import game.model.splashscreen.SplashScreen;
import javax.swing.ImageIcon;
import javax.swing.JLabel;
import javax.swing.JLayeredPane;
import javax.swing.JPanel;

/**
 *
 * @author Gab'z
 */
public class PanelVue extends JLayeredPane {

    private static PanelVue panelVue = null;
    private static PanelPlan panelPlan;
    private static JPanel panelNomLieu;
    private static JLabel flecheNord;
    private static JLabel flecheEst;
    private static JLabel flecheSud;
    private static JLabel flecheOuest;
    private static ControlerPanelVue serveurVue = ControlerPanelVue.getServeurVue();
    private static ServeurFleches serveurFleches = ServeurFleches.getServeurFleches();
    private static GestionnairePlans Gplans = GestionnairePlans.getGP();
    private static String idPlanCourant = null;
    private static PanelSplashScreen panelSplashScreen = null;
    private static PanelFog panelFog;

    private PanelVue() {
        // super();
        System.out.println("Constructeur PanelVue");
        // pour définir le positionnement absolu
        setLayout(null);
        // taille fixe de la fenêtre
        setSize(680, 565);
        // Autres propriétés
        setBorder(javax.swing.BorderFactory.createEtchedBorder());
        // Panel SplashScreen
        panelSplashScreen = PanelSplashScreen.getPanelSplashScreen();
        panelSplashScreen.setLocation(0, 45);
        panelSplashScreen.setBorder(javax.swing.BorderFactory.createEtchedBorder());

    }

    public static PanelVue getPanelVue() {
        if (panelVue == null) {
            panelVue = new PanelVue();
            panelNomLieu = new JPanel();

        }
        return panelVue;
    }

    public static void reloadPanelVue() {
        //setVue(idPlanCourant);
        setVue(EtatJeu.getIdPlanCourant());
        repaintPanelVue();
    }

    public static void repaintPanelVue() {
        panelVue.repaint();
        panelVue.validate();
    }

    public static void setVue(String idPlan) {
        System.out.println("PanelVue.setVue :" + idPlan);
        EtatJeu.setIdPlanCourant(idPlan);//idPlanCourant = idPlan;
        // Réinitialisation de la vue et des flèches
        panelVue.removeAll();
        panelNomLieu = new JPanel();

        // Récupération des infos nécessaires à la création de la vue et des flèches
        Plan plan = Gplans.getPlan(idPlan);


        panelNomLieu.setSize(680, 45);
        panelNomLieu.setLocation(0, 0);
        panelNomLieu.setBorder(javax.swing.BorderFactory.createEtchedBorder());

        JLabel labelNomLieu = new JLabel(plan.getDescription());


        //labelNomLieu.setPreferredSize(new Dimension(680,20));
        labelNomLieu.setHorizontalTextPosition(JLabel.CENTER);
        labelNomLieu.setVerticalTextPosition(JLabel.CENTER);
        labelNomLieu.setBorder(javax.swing.BorderFactory.createEtchedBorder());

        panelNomLieu.add(labelNomLieu);
        panelVue.add(panelNomLieu, new Integer(1));

        // Mise en place de la vue
        panelPlan = serveurVue.getVue(idPlan);
        panelPlan.setLocation(20, 65);
        panelVue.add(panelPlan, new Integer(1));

        // Mise en place des flèches
        flecheNord = serveurFleches.getLabelFleche(idPlan, Plan.NORD);
        flecheNord.setLocation(290, 49);
        flecheNord.setSize(100, 12);
        panelVue.add(flecheNord, new Integer(1));

        flecheEst = serveurFleches.getLabelFleche(idPlan, Plan.EST);
        flecheEst.setLocation(664, 255);
        flecheEst.setSize(12, 100);
        panelVue.add(flecheEst, new Integer(1));

        flecheSud = serveurFleches.getLabelFleche(idPlan, Plan.SUD);
        flecheSud.setLocation(290, 549);
        flecheSud.setSize(100, 12);
        panelVue.add(flecheSud, new Integer(1));

        flecheOuest = serveurFleches.getLabelFleche(idPlan, Plan.OUEST);
        flecheOuest.setLocation(4, 255);
        flecheOuest.setSize(12, 100);
        panelVue.add(flecheOuest, new Integer(1));

        repaintPanelVue();
    }

    public static String getIdPlanCourant() {
        return idPlanCourant;
    }

    public static void afficherPanelSplashScreenInventoriable(ImageIcon imgZoom) {
        panelSplashScreen.setInventoriablePanelSplashScreen(imgZoom);
        panelVue.add(panelSplashScreen, new Integer(2));
        repaintPanelVue();
    }

    public static void removePanelSplashScreen() {
        panelVue.remove(panelSplashScreen);
        repaintPanelVue();
    }

    public static void afficherFog() {
        System.out.println("addFOG");
        panelFog = PanelFog.getPanelFog();
        panelVue.add(panelFog, new Integer(2));
        repaintPanelVue();
    }

    public static void removeFog() {
        System.out.println("removeFOG");
        panelVue.remove(panelFog);
        repaintPanelVue();
    }

    public static void afficherSplashScreen(SplashScreen splashScreen) {
        panelSplashScreen.setPanelSplashScreen(splashScreen);
        panelVue.add(panelSplashScreen, new Integer(2));
        repaintPanelVue();
    }
}
